
use warnings;
use Inline C;
use Test::More 'no_plan';

is(ctrl_frm_cmp_t(1, 0, 0, 1, 1, 2, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(0, 0, 0, 1, 1, 2, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(2, 0, 0, 1, 1, 2, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(3, 0, 0, 1, 1, 2, 1, 2), 0, 'check if the parse conforms with gen.');

is(ctrl_frm_cmp_t(1, 1, 0, 1, 1, 2, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(0, 1, 0, 1, 1, 2, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(2, 1, 0, 1, 1, 2, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(3, 1, 0, 1, 1, 2, 1, 2), 0, 'check if the parse conforms with gen.');

is(ctrl_frm_cmp_t(1, 0, 1, 1, 1, 2, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(0, 0, 1, 1, 1, 2, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(2, 0, 1, 1, 1, 2, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(3, 0, 1, 1, 1, 2, 1, 2), 0, 'check if the parse conforms with gen.');

is(ctrl_frm_cmp_t(1, 0, 0, 0, 1, 2, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(0, 0, 0, 0, 1, 2, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(2, 0, 0, 0, 1, 2, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(3, 0, 0, 0, 1, 2, 1, 2), 0, 'check if the parse conforms with gen.');

is(ctrl_frm_cmp_t(1, 0, 0, 1, 0, 2, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(0, 0, 0, 1, 0, 2, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(2, 0, 0, 1, 0, 2, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(3, 0, 0, 1, 0, 2, 1, 2), 0, 'check if the parse conforms with gen.');

is(ctrl_frm_cmp_t(1, 0, 0, 1, 1, 0, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(0, 0, 0, 1, 1, 0, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(2, 0, 0, 1, 1, 0, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(3, 0, 0, 1, 1, 0, 1, 2), 0, 'check if the parse conforms with gen.');

is(ctrl_frm_cmp_t(1, 0, 0, 1, 1, 3, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(0, 0, 0, 1, 1, 3, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(2, 0, 0, 1, 1, 3, 1, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(3, 0, 0, 1, 1, 3, 1, 2), 0, 'check if the parse conforms with gen.');

is(ctrl_frm_cmp_t(1, 0, 0, 1, 1, 2, 0, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(0, 0, 0, 1, 1, 2, 0, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(2, 0, 0, 1, 1, 2, 0, 2), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(3, 0, 0, 1, 1, 2, 0, 2), 0, 'check if the parse conforms with gen.');

is(ctrl_frm_cmp_t(1, 0, 0, 1, 1, 2, 1, 0), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(0, 0, 0, 1, 1, 2, 1, 0), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(2, 0, 0, 1, 1, 2, 1, 0), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(3, 0, 0, 1, 1, 2, 1, 0), 0, 'check if the parse conforms with gen.');

is(ctrl_frm_cmp_t(1, 0, 0, 1, 1, 2, 1, 3), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(0, 0, 0, 1, 1, 2, 1, 3), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(2, 0, 0, 1, 1, 2, 1, 3), 0, 'check if the parse conforms with gen.');
is(ctrl_frm_cmp_t(3, 0, 0, 1, 1, 2, 1, 3), 0, 'check if the parse conforms with gen.');


# test mac_hdr_cmp_t
$frm_type     = 1;
$en_sec       = 0;
$frm_pend     = 0;
$ack          = 1;
$pan_id_comp  = 1;
$dest_addr_m  = 2;
$frm_ver      = 2;
$src_addr_m   = 2;
$dsn          = 0;
$src_pan_id   = 10;
$dest_pan_id  = 10;
$src_addr     = 10000;
$dest_addr    = 20000;
is(mac_hdr_cmp_t($frm_type, $en_sec, $frm_pend, $ack, $pan_id_comp, $dest_addr_m, $frm_ver, $src_addr_m, $dsn, $src_pan_id, $dest_pan_id, $src_addr, $dest_addr),
    0, 'compare the hdr gen and parse.');

#ack frame
$frm_type     = 2;
$en_sec       = 0;
$frm_pend     = 0;
$ack          = 0;
$pan_id_comp  = 0;
$dest_addr_m  = 0;
$frm_ver      = 2;
$src_addr_m   = 0;
$dsn          = 1;
$src_pan_id   = 0;
$dest_pan_id  = 0;
$src_addr     = 0;
$dest_addr    = 0;
is(mac_hdr_cmp_t($frm_type, $en_sec, $frm_pend, $ack, $pan_id_comp, $dest_addr_m, $frm_ver, $src_addr_m, $dsn, $src_pan_id, $dest_pan_id, $src_addr, $dest_addr),
    0, 'compare the hdr gen and parse.');

# beacon frame
$frm_type     = 0;
$en_sec       = 0;
$frm_pend     = 0;
$ack          = 1;
$pan_id_comp  = 0;
$dest_addr_m  = 3;
$frm_ver      = 2;
$src_addr_m   = 3;
$dsn          = 2;
$src_pan_id   = 10;
$dest_pan_id  = 10;
$src_addr     = 10001;
$dest_addr    = 20001;
is(mac_hdr_cmp_t($frm_type, $en_sec, $frm_pend, $ack, $pan_id_comp, $dest_addr_m, $frm_ver, $src_addr_m, $dsn, $src_pan_id, $dest_pan_id, $src_addr, $dest_addr),
    0, 'compare the hdr gen and parse.');

# cmd frame
$frm_type     = 3;
$en_sec       = 0;
$frm_pend     = 0;
$ack          = 1;
$pan_id_comp  = 1;
$dest_addr_m  = 3;
$frm_ver      = 2;
$src_addr_m   = 3;
$dsn          = 3;
$src_pan_id   = 0;
$dest_pan_id  = 10;
$src_addr     = 0;
$dest_addr    = 20002;
is(mac_hdr_cmp_t($frm_type, $en_sec, $frm_pend, $ack, $pan_id_comp, $dest_addr_m, $frm_ver, $src_addr_m, $dsn, $src_pan_id, $dest_pan_id, $src_addr, $dest_addr),
    0, 'compare the hdr gen and parse.');

# cmd frame
$frm_type     = 3;
$en_sec       = 0;
$frm_pend     = 0;
$ack          = 1;
$pan_id_comp  = 0;
$dest_addr_m  = 2;
$frm_ver      = 2;
$src_addr_m   = 3;
$dsn          = 4;
$src_pan_id   = 10;
$dest_pan_id  = 10;
$src_addr     = 10002;
$dest_addr    = 20002;
is(mac_hdr_cmp_t($frm_type, $en_sec, $frm_pend, $ack, $pan_id_comp, $dest_addr_m, $frm_ver, $src_addr_m, $dsn, $src_pan_id, $dest_pan_id, $src_addr, $dest_addr),
    0, 'compare the hdr gen and parse.');

# cmd frame
$frm_type     = 3;
$en_sec       = 0;
$frm_pend     = 0;
$ack          = 1;
$pan_id_comp  = 0;
$dest_addr_m  = 0;
$frm_ver      = 2;
$src_addr_m   = 3;
$dsn          = 5;
$src_pan_id   = 10;
$dest_pan_id  = 0;
$src_addr     = 10002;
$dest_addr    = 0;
is(mac_hdr_cmp_t($frm_type, $en_sec, $frm_pend, $ack, $pan_id_comp, $dest_addr_m, $frm_ver, $src_addr_m, $dsn, $src_pan_id, $dest_pan_id, $src_addr, $dest_addr),
    0, 'compare the hdr gen and parse.');

# cmd frame
$frm_type     = 3;
$en_sec       = 0;
$frm_pend     = 0;
$ack          = 1;
$pan_id_comp  = 0;
$dest_addr_m  = 2;
$frm_ver      = 2;
$src_addr_m   = 0;
$dsn          = 6;
$src_pan_id   = 0;
$dest_pan_id  = 10;
$src_addr     = 0;
$dest_addr    = 20003;
is(mac_hdr_cmp_t($frm_type, $en_sec, $frm_pend, $ack, $pan_id_comp, $dest_addr_m, $frm_ver, $src_addr_m, $dsn, $src_pan_id, $dest_pan_id, $src_addr, $dest_addr),
    0, 'compare the hdr gen and parse.');

# test mac_sup_frm.
# standard configuration for MAC layer.
$bcn_order = 15;
$sup_frm_order = 0;
$fnl_cap_slot  = 0;
$ble           = 0;
$pan_coord     = 1; # or 0.
$assoc_pmit    = 1; #or 0.
is(sup_frm_cmp_t($bcn_order, $sup_frm_order, $fnl_cap_slot, $ble, $pan_coord, $assoc_pmit),
   0, 'compare the superframe between gen and parse.');

$bcn_order = 15;
$sup_frm_order = 0;
$fnl_cap_slot  = 0;
$ble           = 0;
$pan_coord     = 0;
$assoc_pmit    = 0;
is(sup_frm_cmp_t($bcn_order, $sup_frm_order, $fnl_cap_slot, $ble, $pan_coord, $assoc_pmit),
   0, 'compare the superframe between gen and parse.');

# test mac_cap_info.
# standard configuration.
$altnt_pan_coord  = 1; # 1 if capable of becoming the PAN coordinator.
$dev_type         = 1; # 1 if FFD, 0 if RFD.
$pw_src           = 0;
$rec_on_when_idle = 1;
$sec_cap          = 0;
$alloc_addr       = 1; # wishes the coordinator to allocate a 16-bit short address as a result of the association procedure.
is(cap_info_cmp_t($altnt_pan_coord, $dev_type, $pw_src, $rec_on_when_idle, $sec_cap, $alloc_addr),
   0, 'compare the capability information between gen and parse.');

$altnt_pan_coord  = 0; # 1 if capable of becoming the PAN coordinator.
$dev_type         = 0; # 1 if FFD, 0 if RFD.
$pw_src           = 0;
$rec_on_when_idle = 1;
$sec_cap          = 0;
$alloc_addr       = 0; # wishes the coordinator to allocate a 16-bit short address as a result of the association procedure.
is(cap_info_cmp_t($altnt_pan_coord, $dev_type, $pw_src, $rec_on_when_idle, $sec_cap, $alloc_addr),
   0, 'compare the capability information between gen and parse.');

# test mac_gen_ack() and mac_parse_ack()
$pend = 1;
$dsn = 0;
is(ack_cmp_t($pend, $dsn), 0, 'compare the ack frame between gen and parse.');


# test mac_gen_assoc_req and mac_parse_assoc_req
$src = 0x12001200;
$dest = 0x34003400;
$src_pan_id = 10;
$dest_pan_id = 20;
$cap_info = 0x56;
$dsn = 10;
is(assoc_req_cmp_t($src, $dest, $src_pan_id, $dest_pan_id, $cap_info, $dsn), 0,
   'compare the association request between gen and parse.');

$src = 0x12001201;
$dest = 0x34003401;
$src_pan_id = 11;
$dest_pan_id = 21;
$cap_info = 0x57;
$dsn = 11;
is(assoc_req_cmp_t($src, $dest, $src_pan_id, $dest_pan_id, $cap_info, $dsn), 0,
   'compare the association request between gen and parse.');

$src = 0x12001202;
$dest = 0x34003402;
$src_pan_id = 12;
$dest_pan_id = 22;
$cap_info = 0x58;
$dsn = 12;
is(assoc_req_cmp_t($src, $dest, $src_pan_id, $dest_pan_id, $cap_info, $dsn), 0,
   'compare the association request between gen and parse.');

$src = 0x12001203;
$dest = 0x34003403;
$src_pan_id = 13;
$dest_pan_id = 23;
$cap_info = 0x59;
$dsn = 13;
is(assoc_req_cmp_t($src, $dest, $src_pan_id, $dest_pan_id, $cap_info, $dsn), 0,
   'compare the association request between gen and parse.');


# test mac_gen_assoc_resp and mac_parse_assoc_resp
$src = 0x10001000;
$dest = 0x20002000;
$short_addr = 0x5678;
$status = 0x00;
$dsn = 10;
$pan_id = 0x3000;
is(assoc_resp_cmp_t($src, $dest, $short_addr, $status, $dsn, $pan_id), 0,
    'compare the association response between gen and parse.');

$src = 0x10001001;
$dest = 0x20002001;
$short_addr = 0xffff;
$status = 0x01;
$dsn = 11;
$pan_id = 0x3001;
is(assoc_resp_cmp_t($src, $dest, $short_addr, $status, $dsn, $pan_id), 0,
    'compare the association response between gen and parse.');

$src = 0x10001002;
$dest = 0x20002002;
$short_addr = 0x0000;
$status = 0x02;
$dsn = 13;
$pan_id = 0xffff;
is(assoc_resp_cmp_t($src, $dest, $short_addr, $status, $dsn, $pan_id), 0,
    'compare the association response between gen and parse.');


# test mac_gen_data_req
$src_addr_m = 3;
$src = 0x11001100;
$dest_addr_m = 3;
$dest = 0x88008800;
$pan_id_comp = 1;
$src_pan_id = 0;
$dest_pan_id = 10;
$dsn = 20;
is(data_req_cmp_t($src, $dest, $pan_id_comp, $src_pan_id, $dest_pan_id, $src_addr_m, $dest_addr_m, $dsn), 0,
   'compare the data request between gen and parse.');

$src_addr_m = 3;
$src = 0x11001101;
$dest_addr_m = 2;
$dest = 0x8800;
$pan_id_comp = 1;
$src_pan_id = 0;
$dest_pan_id = 11;
$dsn = 21;
is(data_req_cmp_t($src, $dest, $pan_id_comp, $src_pan_id, $dest_pan_id, $src_addr_m, $dest_addr_m, $dsn), 0,
   'compare the data request between gen and parse.');

$src_addr_m = 0;
$src = 0;
$dest_addr_m = 2;
$dest = 0x1100;
$pan_id_comp = 0;
$src_pan_id = 0;
$dest_pan_id = 0;
$dsn = 22;
is(data_req_cmp_t($src, $dest, $pan_id_comp, $src_pan_id, $dest_pan_id, $src_addr_m, $dest_addr_m, $dsn), 0,
   'compare the data request gen and parse.');


# test mac_gen_bcn_req()
is(bcn_req_cmp_t(0), 0, 'compare beacon request between gen and parse.');
is(bcn_req_cmp_t(1), 0, 'compare beacon request between gen and parse.');
is(bcn_req_cmp_t(2), 0, 'compare beacon request between gen and parse.');
is(bcn_req_cmp_t(3), 0, 'compare beacon request between gen and parse.');
is(bcn_req_cmp_t(4), 0, 'compare beacon request between gen and parse.');
is(bcn_req_cmp_t(5), 0, 'compare beacon request between gen and parse.');


# test mac_gen_bcn()
$pan_id = 0;
$addr = 0x5000;
$bsn = 10;
is(gen_bcn_cmp_t($pan_id, $addr, $bsn), 0, 'compare bcn frame.');
$pan_id = 1;
$addr = 0x5001;
$bsn = 12;
is(gen_bcn_cmp_t($pan_id, $addr, $bsn), 0, 'compare bcn frame.');
$pan_id = 2;
$addr = 0x5002;
$bsn = 12;
is(gen_bcn_cmp_t($pan_id, $addr, $bsn), 0, 'compare bcn frame.');
$pan_id = 3;
$addr = 0x5003;
$bsn = 13;
is(gen_bcn_cmp_t($pan_id, $addr, $bsn), 0, 'compare bcn frame.');
$pan_id = 4;
$addr = 0x5004;
$bsn = 14;
is(gen_bcn_cmp_t($pan_id, $addr, $bsn), 0, 'compare bcn frame.');

__END__
__C__

#include "../../../../mac/mac_parse.h"
#include "../../../../mac/mac_parse.c"
#include "mac_parse_test.c"
#include "../../../../mac/mac_gen.c"

int ctrl_frm_cmp_t(unsigned char frm_type, unsigned char en_sec, unsigned char frm_pend,
        unsigned char ack, unsigned char pan_id_comp, unsigned char dest_addr_m, unsigned char frm_ver,
        unsigned char src_addr_m)
{
    mac_frm_ctrl_t orig;
    uint16 orig_value;

    orig.frm_type     = frm_type;
    orig.en_sec       = en_sec;
    orig.frm_pend     = frm_pend;
    orig.ack          = ack;
    orig.pan_id_comp  = pan_id_comp;
    orig.dest_addr_m  = dest_addr_m;
    orig.frm_ver      = frm_ver;
    orig.src_addr_m   = src_addr_m;

    orig_value = mac_gen_frm_ctrl(&orig);
    /* MAC_DEBUG("orig value is %d\n", orig_value); */

    return frm_ctrl_cmp(orig_value, &orig);
}

int mac_hdr_cmp_t(unsigned char frm_type, unsigned char en_sec, unsigned char frm_pend,
        unsigned char ack, unsigned char pan_id_comp, unsigned char dest_addr_m, unsigned char frm_ver,
        unsigned char src_addr_m, unsigned char dsn, unsigned short src_pan_id,
        unsigned short dest_pan_id, unsigned int src_addr, unsigned int dest_addr)
{
    mac_hdr_t gen_hdr;
    mac_frm_ctrl_t *ctrl = &gen_hdr.ctrl;
    uint16 ctrl_value;
    buf_t buf;


    memset(&gen_hdr, 0, sizeof(mac_hdr_t));
    ctrl->frm_type     = frm_type;
    ctrl->en_sec       = en_sec;
    ctrl->frm_pend     = frm_pend;
    ctrl->ack          = ack;
    ctrl->pan_id_comp  = pan_id_comp;
    ctrl->dest_addr_m  = dest_addr_m;
    ctrl->frm_ver      = frm_ver;
    ctrl->src_addr_m   = src_addr_m;

    /*
    MAC_DEBUG("\nmac_hdr_cmp_t****pan_id_comp is %d\n", pan_id_comp);
    */

    gen_hdr.dsn = dsn;
    gen_hdr.src_pan_id = src_pan_id;
    gen_hdr.dest_pan_id = dest_pan_id;
    if (src_addr_m == ADDR_64_M) {
        gen_hdr.src_addr.a.addr64 = src_addr;
    } else if (src_addr_m == ADDR_16_M) {
        gen_hdr.src_addr.a.addr16 = src_addr;
    }
    if (dest_addr_m == ADDR_64_M) {
        gen_hdr.dest_addr.a.addr64 = dest_addr;
    } else if (dest_addr_m == ADDR_16_M) {
        gen_hdr.dest_addr.a.addr16 = dest_addr;
    }
    /*
    MAC_DEBUG("dsn:%d\tsrc_pan_id:%d\tdest_pan_id:%d\tsrc_addr:%d\tdest_addr:%d\t\n",
            dsn,
            src_pan_id,
            dest_pan_id,
            src_addr,
            dest_addr,
            dest_addr
          );

    MAC_DEBUG("gen_hdr.dsn is %d\n", gen_hdr.dsn);
    MAC_DEBUG("gen_hdr.src_pan_id is %d\n", gen_hdr.src_pan_id);
    MAC_DEBUG("gen_hdr.dest_pan_id is %d\n", gen_hdr.dest_pan_id);
    MAC_DEBUG("gen_hdr.src_addr.a.addr64 %d\n", (int)gen_hdr.src_addr.a.addr64);
    MAC_DEBUG("gen_hdr.src_addr.a.addr16 is %d\n", gen_hdr.src_addr.a.addr16);
    MAC_DEBUG("gen_hdr.dest_addr.a.addr64 is %d\n", (int)gen_hdr.dest_addr.a.addr64);
    MAC_DEBUG("gen_hdr.dest_addr.a.addr16 is %d\n", gen_hdr.dest_addr.a.addr16);
    */

    /* initialize the buf */
    buf.ptr = &buf.array[127];
    buf.length = 0;

    mac_gen_hdr(&buf, &gen_hdr);
    return mac_hdr_cmp(&buf, &gen_hdr);
}

int sup_frm_cmp_t(unsigned char bcn_order, unsigned char sup_frm_order,
                  unsigned char fnl_cap_slot, unsigned char ble,
                  unsigned char pan_coord, unsigned char assoc_pmit)
{
    mac_sup_frm_t gen;
    uint16 value;

    gen.bcn_order       = bcn_order;
    gen.sup_frm_order   = sup_frm_order;
    gen.fnl_cap_slot    = fnl_cap_slot;
    gen.ble             = ble;
    gen.pan_coord       = pan_coord;
    gen.assoc_pmit      = assoc_pmit;

    value = mac_gen_sup_frm(&gen);
    return sup_frm_cmp(value, &gen);
}

int cap_info_cmp_t(unsigned char altnt_pan_coord, unsigned char dev_type,
                 unsigned char pw_src,          unsigned char rec_on_when_idl,
                 unsigned char sec_cap,         unsigned char alloc_addr)
{
    mac_cap_info_t gen;
    uint8 value;

    gen.altnt_pan_coord  = altnt_pan_coord;
    gen.dev_type         = dev_type;
    gen.pw_src           = pw_src;
    gen.rec_on_when_idle = rec_on_when_idl;
    gen.sec_cap          = sec_cap;
    gen.alloc_addr       = alloc_addr;

    value = mac_gen_cap_info(&gen);

    return cap_info_cmp(value, &gen);
}

int ack_cmp_t(unsigned char pend, unsigned char dsn)
{
    mac_frm_ack_t ack;
    ack.pend = pend;
    ack.dsn = dsn;
    /*
    MAC_DEBUG("ack_cmp_t: pend is %d, dsn is %d\n", pend, dsn);
    */

    return ack_cmp(&ack);
}

int assoc_req_cmp_t(unsigned int src, unsigned int dest, unsigned char src_pan_id,
                    unsigned char dest_pan_id, unsigned char cap_info, unsigned char dsn)
{
    mac_frm_assoc_req_t req;

    req.src.mode = ADDR_64_M;
    req.src.a.addr64 = src;
    req.dest.mode = ADDR_64_M;
    req.dest.a.addr64 = dest;
    req.src_pan_id = src_pan_id;
    req.dest_pan_id = dest_pan_id;
    req.cap_info = cap_info;
    req.dsn = dsn;
    
    return assoc_req_cmp(&req);
}

int assoc_resp_cmp_t(unsigned int src, unsigned int dest, unsigned short short_addr,
                     unsigned char status, unsigned char dsn, unsigned short pan_id)
{
    mac_frm_assoc_resp_t resp;

    resp.src.mode = ADDR_64_M;
    resp.src.a.addr64 = src;
    resp.dest.mode = ADDR_64_M;
    resp.dest.a.addr64 = dest;
    resp.short_addr = short_addr;
    resp.status = status;
    resp.dsn = dsn;
    resp.pan_id = pan_id;

    return assoc_resp_cmp(&resp);
}

int data_req_cmp_t(unsigned int src, unsigned int dest, unsigned char pan_id_comp,
                   unsigned short src_pan_id, unsigned short dest_pan_id,
                   unsigned char src_addr_m, unsigned char dest_addr_m,
                   unsigned char dsn)
{
    mac_frm_data_req_t req;

    req.src.mode = src_addr_m;
    if (req.src.mode == ADDR_64_M) {
        req.src.a.addr64 = src;
    } else if (req.src.mode == ADDR_16_M) {
        req.src.a.addr16 = (uint16)src;
    }

    req.dest.mode = dest_addr_m;
    if (req.dest.mode == ADDR_64_M) {
        req.dest.a.addr64 = dest;
    } else if (req.dest.mode == ADDR_16_M) {
        req.dest.a.addr16 = (uint16)dest;
    }

    req.pan_id_comp = pan_id_comp;
    req.src_pan_id = src_pan_id;
    req.dest_pan_id = dest_pan_id;
    req.dsn = dsn;

    return data_req_cmp(&req);
}

int bcn_req_cmp_t(unsigned char dsn)
{
    return bcn_req_cmp(dsn);
}

int gen_bcn_cmp_t(unsigned short pan_id, unsigned short addr,
                  unsigned char bsn)
{
    buf_t buf;
    mac_hdr_t hdr;
    mac_frm_ctrl_t *ctrl = &hdr.ctrl;
    uint16 sup_frm_value;
    uint16 parse_sup_frm_value;
    uint16 self_pan_id;
    mac_frm_bcn_t bcn;
    mac_frm_bcn_t parse;

    memset(&buf.array[0], 0, 128);
    buf.ptr = &buf.array[127];
    buf.length = 0;

    bcn.pan_id = pan_id;
    bcn.src.mode = ADDR_16_M;
    bcn.src.a.addr16 = addr;
    bcn.sup_frm_value = 0x1234;
    bcn.bsn = bsn;

    mac_gen_bcn(&buf, &bcn);
    mac_parse_hdr(&buf, &hdr);

    mac_parse_bcn(&buf, &parse);

    /*
    MAC_DEBUG("hdr.dsn               is %d\n", hdr.dsn               );
    MAC_DEBUG("hdr.src_pan_id        is %d\n", hdr.src_pan_id        );
    MAC_DEBUG("hdr.src_addr.a.addr16 is 0x%x\n", hdr.src_addr.a.addr16 );
    MAC_DEBUG("ctrl->frm_type        is %d\n", ctrl->frm_type        );
    MAC_DEBUG("ctrl->en_sec          is %d\n", ctrl->en_sec          );
    MAC_DEBUG("ctrl->ack             is %d\n", ctrl->ack             );
    MAC_DEBUG("ctrl->frm_pend        is %d\n", ctrl->frm_pend        );
    MAC_DEBUG("ctrl->pan_id_comp     is %d\n", ctrl->pan_id_comp     );
    MAC_DEBUG("ctrl->dest_addr_m     is %d\n", ctrl->dest_addr_m     );
    MAC_DEBUG("ctrl->frm_ver         is %d\n", ctrl->frm_ver         );
    MAC_DEBUG("ctrl->src_addr_m      is %d\n", ctrl->src_addr_m      );
    MAC_DEBUG("parse.sup_frm_value   is 0x%x\n", parse.sup_frm_value );
    */

    if (/*hdr.dsn == bsn &&*/
        ctrl->frm_type     == FRM_TYPE_BCN          &&
        ctrl->en_sec       == 0                        && 
        ctrl->ack          == 0                        &&
        ctrl->frm_pend     == 0                        &&
        ctrl->pan_id_comp  == 0                        &&
        ctrl->dest_addr_m  == 0                        &&
        ctrl->frm_ver      == V_2006                   &&
        ctrl->src_addr_m   == ADDR_16_M                &&
        hdr.src_addr.a.addr16 == bcn.src.a.addr16   &&
        parse.sup_frm_value == bcn.sup_frm_value) {

        return 0;
    } else {
        return -1;
    }
}

